<template>
	<!-- 行业服务 -->
	<view class="cpzy-list">
		<!-- 加载状态 -->
		<view v-if="loading" class="loading-container">
			<uni-load-more status="loading" />
		</view>
		
		<!-- 数据列表 -->
		<view v-else-if="cpzyData && cpzyData.length > 0" class="data-list">
			<view class="row" v-for="(item, index) in cpzyData" :key="index" @click="handleClick(item)">
				<view class="left">
					<view class="title">{{ item.qyxqms || item.companyName }}</view>
					<view class="business">{{ item.zyyw || item.qyjj }}</view>
					<view class="view-count">
						<uni-icons type="eye" size="14"></uni-icons>
						<view class="uni-icons-text">{{ item.xyyfServiceLookList && item.xyyfServiceLookList.length || 0 }}
						</view>
					</view>
				</view>
				<view class="right">
					<image :src="item.qyjjXp || '/static/images/head_default.png'" mode="aspectFit"></image>
				</view>
			</view>
		</view>
		
		<!-- 空数据状态 -->
		<view v-else class="empty-container">
			<image src="/static/images/head_default.png" mode="widthFix" class="empty-image"></image>
			<view class="empty-text">暂无行业服务数据</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "Hyfw",
		data() {
			return {
				loading: false
			};
		},
		props: {
			cpzyData: {
				type: Array,
				default: () => []
			}
		},
		watch: {
			cpzyData: {
				handler(newVal) {
					// 当数据变化时，可以在这里添加一些逻辑
					console.log('行业服务数据更新，数量:', newVal.length)
				},
				immediate: true
			}
		},
		methods: {
			handleClick(item) {
				// 检查登录状态
				if (!this.$store.state.user.isLoggedIn) {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					});
					// 跳转到登录页面
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}, 1500);
					return;
				}
				
				if (!item.guid) {
					uni.showToast({
						title: '数据异常，无法查看详情',
						icon: 'none'
					})
					return
				}
				
				uni.navigateTo({
					url: `/pages/service-provider-details/service-provider-details?guid=${item.guid}&text='行业服务'`
				});
			}
		}
	}
</script>

<style lang="less">
	.cpzy-list {
		padding: 10rpx 30rpx 20rpx;
		min-height: 400rpx;

		.loading-container {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 100rpx 0;
		}

		.empty-container {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 100rpx 0;

			.empty-image {
				width: 200rpx;
				height: 200rpx;
				opacity: 0.5;
				margin-bottom: 30rpx;
			}

			.empty-text {
				font-size: 28rpx;
				color: #999;
			}
		}

		.data-list {
			.row {
				position: relative;
				display: flex;
				padding: 20rpx 0 20rpx;
				border-bottom: 1rpx solid #f0f0f0;

				&:last-child {
					border-bottom: none;
				}

				.left {
					flex: 1;
					display: flex;
					flex-direction: column;
					margin-right: 30rpx;

					.title {
						font-size: 32rpx;
						color: #000;
						font-weight: bold;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;
						text-overflow: ellipsis;
						margin-bottom: 10rpx;
					}

					.business {
						font-size: 28rpx;
						color: #333;
						min-height: 50rpx;
						margin-top: 20rpx;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						text-overflow: ellipsis;
						line-height: 1.4;
					}

					.view-count {
						display: flex;
						align-items: center;
						justify-content: flex-start;
						font-size: 28rpx;
						color: #333;
						margin-top: 20rpx;

						.uni-icons-text {
							margin-left: 10rpx;
						}
					}
				}

				.right {
					flex-shrink: 0;
					height: 180rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;

					image {
						width: 240rpx;
						height: 180rpx;
						border-radius: 10rpx;
						background-color: #f5f5f5;
					}
				}
			}
		}
	}
</style>